﻿using System;
using System.ComponentModel.Composition;
using System.IO;
using ExcelDna.Integration;

namespace Cubicle.Nuget.Config
{
    public class InstallPathFinder
    {

        private const string _packagePath = @".\packages";
        private const string _binPath = "";

        [Export]
        public static InstallPathFinder Singleton;

        static InstallPathFinder()
        {
            Singleton = new InstallPathFinder();
        }

        private InstallPathFinder() {}

        [Export("PackagePath")]
        public string PackagePath
        {
            get
            {
                return Path.IsPathRooted(_packagePath)
                           ? _packagePath
                           : Path.GetFullPath(Path.Combine(BasePath, _packagePath));
            }
        }

        [Export("BinPath")]
        public string BinPath
        {
            get
            {
                return Path.IsPathRooted(_binPath)
                           ? _binPath
                           : Path.GetFullPath(Path.Combine(BasePath, _binPath));
            }
        }

        private string BasePath
        {
            get
            {
                return AppDomain.CurrentDomain.BaseDirectory;
                //object baseDir;
                // var returnVal = XlCall.TryExcel(XlCall.xlGetName, out baseDir);
                //return returnVal == XlCall.XlReturn.XlReturnFailed
                //           ? Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)
                //           : Path.GetDirectoryName((string)baseDir);
            }
        }
        
    }
}